<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>纯css实现奥运五环（交叉效果） | Jaho’s Blog</title>
    <meta name="generator" content="VuePress 1.8.0">
    <link rel="icon" href="/favicon.ico">
    <link rel="manifest" href="/manifest.json">
    <meta name="description" content="记录日常学习工作">
    
    <link rel="preload" href="/assets/css/0.styles.5b8fe0a4.css" as="style"><link rel="preload" href="/assets/js/app.6514719e.js" as="script"><link rel="preload" href="/assets/js/2.ea114ffb.js" as="script"><link rel="preload" href="/assets/js/15.08b381b6.js" as="script"><link rel="preload" href="/assets/js/4.e093c564.js" as="script"><link rel="prefetch" href="/assets/js/10.13203aa5.js"><link rel="prefetch" href="/assets/js/11.099868c4.js"><link rel="prefetch" href="/assets/js/12.c8365e17.js"><link rel="prefetch" href="/assets/js/13.89751e7c.js"><link rel="prefetch" href="/assets/js/14.31f563eb.js"><link rel="prefetch" href="/assets/js/16.1a3867de.js"><link rel="prefetch" href="/assets/js/17.7dd4e0c6.js"><link rel="prefetch" href="/assets/js/18.907c4597.js"><link rel="prefetch" href="/assets/js/19.fac8aa1a.js"><link rel="prefetch" href="/assets/js/20.73fe0e75.js"><link rel="prefetch" href="/assets/js/21.5c50aa1c.js"><link rel="prefetch" href="/assets/js/22.83d03663.js"><link rel="prefetch" href="/assets/js/23.061e7ac0.js"><link rel="prefetch" href="/assets/js/24.cc7e9011.js"><link rel="prefetch" href="/assets/js/25.fa6c7aef.js"><link rel="prefetch" href="/assets/js/26.39392f70.js"><link rel="prefetch" href="/assets/js/27.204436be.js"><link rel="prefetch" href="/assets/js/28.3f54c157.js"><link rel="prefetch" href="/assets/js/29.799d048c.js"><link rel="prefetch" href="/assets/js/3.6c5d6214.js"><link rel="prefetch" href="/assets/js/30.deed02f3.js"><link rel="prefetch" href="/assets/js/31.5916873b.js"><link rel="prefetch" href="/assets/js/32.b0634144.js"><link rel="prefetch" href="/assets/js/33.734675b8.js"><link rel="prefetch" href="/assets/js/34.20404dc4.js"><link rel="prefetch" href="/assets/js/35.d93b829f.js"><link rel="prefetch" href="/assets/js/36.b0692d8d.js"><link rel="prefetch" href="/assets/js/37.3dffa306.js"><link rel="prefetch" href="/assets/js/38.04649a97.js"><link rel="prefetch" href="/assets/js/39.7dfcdc32.js"><link rel="prefetch" href="/assets/js/40.04914511.js"><link rel="prefetch" href="/assets/js/41.ced85449.js"><link rel="prefetch" href="/assets/js/42.72739213.js"><link rel="prefetch" href="/assets/js/43.de1cff16.js"><link rel="prefetch" href="/assets/js/44.48e301ae.js"><link rel="prefetch" href="/assets/js/45.870a7650.js"><link rel="prefetch" href="/assets/js/46.657f15b8.js"><link rel="prefetch" href="/assets/js/47.3df1bfdb.js"><link rel="prefetch" href="/assets/js/48.f4e4e774.js"><link rel="prefetch" href="/assets/js/49.632bf611.js"><link rel="prefetch" href="/assets/js/5.6531e181.js"><link rel="prefetch" href="/assets/js/50.a8018493.js"><link rel="prefetch" href="/assets/js/51.cb424f59.js"><link rel="prefetch" href="/assets/js/52.a9f595dc.js"><link rel="prefetch" href="/assets/js/53.cf8a9ec0.js"><link rel="prefetch" href="/assets/js/54.46d774a3.js"><link rel="prefetch" href="/assets/js/55.3574f9b8.js"><link rel="prefetch" href="/assets/js/56.baf60ba5.js"><link rel="prefetch" href="/assets/js/57.af42b559.js"><link rel="prefetch" href="/assets/js/58.9300cb59.js"><link rel="prefetch" href="/assets/js/6.00f437ec.js"><link rel="prefetch" href="/assets/js/7.58ac7166.js"><link rel="prefetch" href="/assets/js/8.1b9c5002.js"><link rel="prefetch" href="/assets/js/9.5c076362.js">
    <link rel="stylesheet" href="/assets/css/0.styles.5b8fe0a4.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="Jaho’s Blog" class="logo"> <span class="site-name can-hide">Jaho’s Blog</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/posts/" class="nav-link router-link-active">
  技术博客
</a></div> <a href="https://juejin.cn/user/26836627369806" target="_blank" rel="noopener noreferrer" class="repo-link">
    个人主页
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/posts/" class="nav-link router-link-active">
  技术博客
</a></div> <a href="https://juejin.cn/user/26836627369806" target="_blank" rel="noopener noreferrer" class="repo-link">
    个人主页
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><a href="/posts/" aria-current="page" class="sidebar-link">写在前面</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>工作问题解决</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>JavaScript</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Css</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/posts/Css/css变量实践.html" class="sidebar-link">css变量实践</a></li><li><a href="/posts/Css/css2.html" class="sidebar-link">页面导入样式时，使用link和@import有什么区别</a></li><li><a href="/posts/Css/css3.html" class="sidebar-link">图片蒙版放大</a></li><li><a href="/posts/Css/css4.html" aria-current="page" class="active sidebar-link">纯css实现奥运五环（交叉效果）</a></li><li><a href="/posts/Css/css5.html" class="sidebar-link">css实现小风车</a></li><li><a href="/posts/Css/css6.html" class="sidebar-link">css实现许愿墙功能</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Nodejs</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Vue</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Git</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="纯css实现奥运五环-交叉效果"><a href="#纯css实现奥运五环-交叉效果" class="header-anchor">#</a> 纯css实现奥运五环（交叉效果）</h1> <blockquote><p>本文写一个简单的css小demo记录一下奥运五环的场景</p></blockquote> <blockquote><p>本文使用vue3来进行编辑，为了熟悉vue3和参加掘金的码上掘金活动，这几天我会抽空多更新几个模块来进行写dome，写的时间比较有限，所以Ui也是尽量从简，功能还是比较完善的。文章的内容不多，欢迎大家阅读和批评指正。</p></blockquote> <blockquote><p>偶然间看到了用动画库或者canvas实现的一例奥运五环，通过查找资料看到了其实奥运五环也可以通过css来进行实现，为了更好的提高手写css的能力，又用这个实例来练习一下，其实采用到的主要的方法只是俩个简单的css属性，一个是transform-style: preserve-3d;和transform: rotateX(-1deg);通过旋转的方式来实现圆圈之间的叠加效果，也就是环环相扣的效果</p></blockquote> <div class="language-js extra-class"><pre class="language-js"><code> <span class="token punctuation">.</span>c1<span class="token punctuation">{</span>
        <span class="token literal-property property">border</span><span class="token operator">:</span> 5px solid red<span class="token punctuation">;</span>
        <span class="token literal-property property">top</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token literal-property property">left</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token literal-property property">transform</span><span class="token operator">:</span> <span class="token function">rotateX</span><span class="token punctuation">(</span><span class="token operator">-</span>10deg<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">.</span>c4<span class="token punctuation">{</span>
    <span class="token literal-property property">border</span><span class="token operator">:</span> 5px solid orange<span class="token punctuation">;</span>
    <span class="token literal-property property">top</span><span class="token operator">:</span> 50px<span class="token punctuation">;</span>
    <span class="token literal-property property">left</span><span class="token operator">:</span> 53px<span class="token punctuation">;</span>
    <span class="token literal-property property">transform</span><span class="token operator">:</span> <span class="token function">rotateX</span><span class="token punctuation">(</span>10deg<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre></div><p><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/383aa1fa9cf64361b2f586f3ea3bad54~tplv-k3u1fbpfcp-watermark.image?" alt="image.png"></p> <blockquote><p>对其中的第一个红色的环进行x轴的旋转，然后对应的第四个橙色的环，做出相反方向的旋转，一个是正值一个是负值，在平面上两个环是平行的，但在3d效果上看，一个向内弯，一个向外弯，由于有偏向角度的原因，那么这样的圆形其实是有点稍微扁的，但是肉眼上是看不出来很大的区别。</p></blockquote> <blockquote><p>分别对五个环进行不同方向的偏移，建议开发的时候在控制台进行调试，不熟悉3d旋转的朋友可以在控制台边调试边看，就能找准合适的角度</p></blockquote> <div class="language-js extra-class"><pre class="language-js"><code><span class="token operator">&lt;</span>style<span class="token operator">&gt;</span>
    <span class="token punctuation">.</span>box<span class="token punctuation">{</span>
        <span class="token literal-property property">width</span><span class="token operator">:</span> 330px<span class="token punctuation">;</span>
        <span class="token literal-property property">height</span><span class="token operator">:</span> 300px<span class="token punctuation">;</span>
        <span class="token literal-property property">margin</span><span class="token operator">:</span> 20px<span class="token punctuation">;</span>
        <span class="token literal-property property">position</span><span class="token operator">:</span> relative<span class="token punctuation">;</span>
        transform<span class="token operator">-</span>style<span class="token operator">:</span> preserve<span class="token operator">-</span>3d<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span>cycle<span class="token punctuation">{</span>
        <span class="token literal-property property">width</span><span class="token operator">:</span> 80px<span class="token punctuation">;</span>
        <span class="token literal-property property">height</span><span class="token operator">:</span> 80px<span class="token punctuation">;</span>
        border<span class="token operator">-</span>radius<span class="token operator">:</span> <span class="token number">50</span><span class="token operator">%</span><span class="token punctuation">;</span>
        <span class="token literal-property property">position</span><span class="token operator">:</span> absolute<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span>c1<span class="token punctuation">{</span>
        <span class="token literal-property property">border</span><span class="token operator">:</span> 10px solid red<span class="token punctuation">;</span>
        <span class="token literal-property property">top</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token literal-property property">left</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token literal-property property">transform</span><span class="token operator">:</span> <span class="token function">rotateX</span><span class="token punctuation">(</span><span class="token operator">-</span>1deg<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span>c2<span class="token punctuation">{</span>
        <span class="token literal-property property">border</span><span class="token operator">:</span> 10px solid gray<span class="token punctuation">;</span>
        <span class="token literal-property property">top</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token literal-property property">left</span><span class="token operator">:</span> 120px<span class="token punctuation">;</span>
        <span class="token literal-property property">transform</span><span class="token operator">:</span> <span class="token function">rotateX</span><span class="token punctuation">(</span>3deg<span class="token punctuation">)</span> <span class="token function">rotateY</span><span class="token punctuation">(</span><span class="token operator">-</span>3deg<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span>c3<span class="token punctuation">{</span>
        <span class="token literal-property property">border</span><span class="token operator">:</span> 10px solid green<span class="token punctuation">;</span>
        <span class="token literal-property property">top</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token literal-property property">right</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token literal-property property">transform</span><span class="token operator">:</span> <span class="token function">rotateY</span><span class="token punctuation">(</span><span class="token operator">-</span>6deg<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span>c4<span class="token punctuation">{</span>
        <span class="token literal-property property">border</span><span class="token operator">:</span> 10px solid orange<span class="token punctuation">;</span>
        <span class="token literal-property property">top</span><span class="token operator">:</span> 50px<span class="token punctuation">;</span>
        <span class="token literal-property property">left</span><span class="token operator">:</span> 57px<span class="token punctuation">;</span>
        <span class="token literal-property property">transform</span><span class="token operator">:</span> <span class="token function">rotateX</span><span class="token punctuation">(</span>1deg<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span>c5<span class="token punctuation">{</span>
        <span class="token literal-property property">border</span><span class="token operator">:</span> 10px solid blue<span class="token punctuation">;</span>
        <span class="token literal-property property">top</span><span class="token operator">:</span> 50px<span class="token punctuation">;</span>
        <span class="token literal-property property">right</span><span class="token operator">:</span> 57px<span class="token punctuation">;</span>
        <span class="token literal-property property">transform</span><span class="token operator">:</span> <span class="token function">rotateX</span><span class="token punctuation">(</span>3deg<span class="token punctuation">)</span> <span class="token function">rotateY</span><span class="token punctuation">(</span>5deg<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

  <span class="token operator">&lt;</span><span class="token operator">/</span>style<span class="token operator">&gt;</span>
</code></pre></div><blockquote><p>上面这个是我css的实现，3d旋转的前提是要在父元素加一个transform-style: preserve-3d的css，这样内部的子元素才能达到3d旋转的效果</p></blockquote></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023-01-09 17:42:20</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/posts/Css/css3.html" class="prev">
        图片蒙版放大
      </a></span> <span class="next"><a href="/posts/Css/css5.html">
        css实现小风车
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----><!----></div></div>
    <script src="/assets/js/app.6514719e.js" defer></script><script src="/assets/js/2.ea114ffb.js" defer></script><script src="/assets/js/15.08b381b6.js" defer></script><script src="/assets/js/4.e093c564.js" defer></script>
  </body>
</html>
